/*
 * geoTrans.cpp
 *
 *  Created on: 2011-2-28
 *      Author: tom
 */

#include "geoTrans.h"

GeoTrans::GeoTrans(const IplImage* const image){
	this->image=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
	cvCopy(image,this->image);
}

GeoTrans::~GeoTrans(){
	cvReleaseImage(&image);
}

void GeoTrans::zoom(double scaler){
	IplImage* result=cvCreateImage(cvSize(image->width*scaler,image->height*scaler),image->depth,image->nChannels);
	
	cvResize(image,result);
	
	cvNamedWindow("zoom");
	cvShowImage("zoom",result);
	cvWaitKey(0);
	
	cvReleaseImage(&result);
	cvDestroyWindow("zoom");
}

void GeoTrans::rotate(double angle,double scaler){
	IplImage* result=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
	CvMat* rotateMat=cvCreateMat(2,3,CV_32FC1);
	
	cv2DRotationMatrix(cvPoint2D32f(image->width/2.,image->height/2.),angle,scaler,rotateMat);
	cvWarpAffine(image,result,rotateMat);
	
	cvNamedWindow("rotate");
	cvShowImage("rotate",result);
	cvWaitKey(0);
	
	cvReleaseImage(&result);
	cvReleaseMat(&rotateMat);
	cvDestroyWindow("rotate");
}

void GeoTrans::mirror(){
	IplImage* dst=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
	
	cvFlip(image,dst,1);
	
	cvNamedWindow("mirror");
	cvShowImage("mirror",dst);
	cvWaitKey(0);
	
	cvReleaseImage(&dst);
	cvDestroyWindow("mirror");
}

void GeoTrans::flip(){
	IplImage* dst=cvCreateImage(cvGetSize(image),image->depth,image->nChannels);
	
	cvFlip(image,dst,0);
	
	cvNamedWindow("flip");
	cvShowImage("flip",dst);
	cvWaitKey(0);
	
	cvReleaseImage(&dst);
	cvDestroyWindow("flip");
}
